package com.jp.knowledge.model;

import com.google.gson.internal.LinkedTreeMap;
import com.jp.knowledge.util.JsonUtil;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author: jiayen
 * @Data: 16/4/12 下午2:35
 * @Description: java模型基类
 */
public class IModel implements Serializable{

    private int errcode;
    private String message;
//    private String data;
    private String uptoken;

    private Object data;

    public int getErrcode() {
        return errcode;
    }

    public void setErrcode(int errcode) {
        this.errcode = errcode;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {this.data = data;}

    public <T extends Object> List<T> getList(Class<T> clazz){
        try {
            return  JsonUtil.getInstance().listMapToObject((ArrayList<LinkedTreeMap<String, Object>>) data,clazz);
        }catch (Exception e){
            return  null;
        }

    }

    public String getUptoken() {
        return uptoken;
    }

    public void setUptoken(String uptoken) {
        this.uptoken = uptoken;
    }

    public <T extends Object> T getEntity(Class<T> clazz){
        return JsonUtil.getInstance().mapToObject((LinkedTreeMap<String, Object>) data,clazz);
    }
    @Override
    public String toString() {
        return "IModel{" +
                "errcode=" + errcode +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}
